/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.skill.executor;

import com.lineage.server.PacketCreate;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.skill.L1SkillExecutor;
import com.lineage.server.packetserver.S_OwnCharAttrDef;
import com.lineage.server.packetserver.S_SkillSound;
import com.lineage.server.packetserver.ServerBasePacket;

/**
 * Class <code>ElementalFalldown</code> 精灵魔法:弱化属性(10/0).
 * 持续时间内，目标的属性防御力降低50%。目标降低的属性与自身的属性相同
 * 
 * @author jrwz
 * @version 2012-7-24下午03:22:10
 * @see com.lineage.server.model.skill.executor
 * @since JDK1.7
 */
public final class ElementalFalldown extends L1SkillExecutor {
    /** 地属性. */
    private static final int EARTH = 1;
    /** 火属性. */
    private static final int FIRE = 2;
    /** 水属性. */
    private static final int WATER = 4;
    /** 风属性. */
    private static final int WIND = 8;

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static L1SkillExecutor get() {
        return new ElementalFalldown();
    }

    /** 精灵魔法:弱化属性(10/0). */
    private ElementalFalldown() {
    }

    @Override
    public void execute(final L1Character user, final L1Character cha,
            final L1Character target, final int targetID, final int skillId,
            final int getBuffIconDuration) {
        if (user instanceof L1PcInstance) {
            final L1PcInstance pc = (L1PcInstance) user;
            final int playerAttr = pc.getElfAttr();
            final int i = -50;
            if (playerAttr != 0) {
                final ServerBasePacket s = new S_SkillSound(cha.getId(), 4396);
                pc.sendPackets(s);
                pc.broadcastPacket(s);
            }
            switch (playerAttr) {
                case 0:
                    PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
                    break;
                case EARTH:
                    cha.addEarth(i);
                    cha.setAddAttrKind(EARTH);
                    break;
                case FIRE:
                    cha.addFire(i);
                    cha.setAddAttrKind(FIRE);
                    break;
                case WATER:
                    cha.addWater(i);
                    cha.setAddAttrKind(WATER);
                    break;
                case WIND:
                    cha.addWind(i);
                    cha.setAddAttrKind(WIND);
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    public void stop(final L1Character cha, final int skillId) {
        final int attr = cha.getAddAttrKind();
        final int i = 50;
        switch (attr) {
            case EARTH:
                cha.addEarth(i);
                break;
            case FIRE:
                cha.addFire(i);
                break;
            case WATER:
                cha.addWater(i);
                break;
            case WIND:
                cha.addWind(i);
                break;
            default:
                break;
        }
        cha.setAddAttrKind(0);
        if (cha instanceof L1PcInstance) {
            final L1PcInstance pc = (L1PcInstance) cha;
            pc.sendPackets(new S_OwnCharAttrDef(pc));
        }
    }
}
